package com.shhm.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.shhm.admin.mapper.MenuMapper;
import com.shhm.admin.service.MenuService;
import com.shhm.admin.util.RequestUtil;
import com.shhm.common.dto.request.RequestList;
import com.shhm.common.dto.response.AjaxResultPlus;
import com.shhm.common.entity.admin.MenuEntity;
import com.shhm.common.mapper.SysRoleOperatePermsMapper;
import com.shhm.common.utils.MybatisPlusUtil;
import com.shhm.common.utils.ResponseUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author JackZ
 * @version 1.0
 * @description: TODO
 * @date 2025/8/14 下午2:12
 */
@Service
public class MenuServiceImpl implements MenuService {
    @Resource
    private MenuMapper menuMapper;
    @Resource
    private SysRoleOperatePermsMapper roleOperatePermsMapper;

    @Override
    public AjaxResultPlus pageList(Integer pageNum, Integer pageSize, Integer isPage,HttpServletRequest request) {
        if (isPage==0) {
            LambdaQueryWrapper<MenuEntity> qw = new LambdaQueryWrapper<MenuEntity>().select(MenuEntity::getMenuId, MenuEntity::getMenuName,MenuEntity::getName);
            List<MenuEntity> list = menuMapper.selectList(qw);
            return AjaxResultPlus.success(list,false);
        }
        PageDTO<MenuEntity> userPage = new PageDTO<>(pageNum, pageSize);
        PageDTO<MenuEntity> list=menuMapper.selectPage(userPage, null);
        return AjaxResultPlus.custom(200, false)
                .put("data",list);
    }

    @Override
    public AjaxResultPlus pageSearchList(Integer pageNum, Integer pageSize, MenuEntity entity) {
        PageDTO<MenuEntity> userPage = new PageDTO<>(pageNum, pageSize);
        QueryWrapper<MenuEntity> qw = MybatisPlusUtil.buildSearchQueryWrapper(entity);
        PageDTO<MenuEntity> list = menuMapper.selectPage(userPage, qw);
        return AjaxResultPlus.success(list,false);
    }

    @Override
    public AjaxResultPlus add(MenuEntity entity) {
        return ResponseUtil.sqlExeIsSuccess(menuMapper.insert(entity));
    }

    @Override
    public AjaxResultPlus update(MenuEntity entity) {
        return ResponseUtil.sqlExeIsSuccess(menuMapper.updateById(entity));
    }

    @Override
    public AjaxResultPlus delete(RequestList ids) {
        List<Object> list = ids.getList();
        return ResponseUtil.sqlExeIsSuccess(menuMapper.deleteByIds(list));
    }
}
